package xxhui.space.newsclient.Fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import xxhui.space.newsclient.Bean.User;
import xxhui.space.newsclient.InterFacez.MeFragmentCallback;
import xxhui.space.newsclient.MeInfoActivity;
import xxhui.space.newsclient.R;
import xxhui.space.newsclient.util.MyApplication;

/**
 * A simple {@link Fragment} subclass.
 */
public class MeFragment extends Fragment implements MeFragmentCallback {

    @BindView(R.id.me_edit_info)
    ImageView edit;
    @BindView(R.id.me_user_name)
    TextView userName;
    @BindView(R.id.item_user_pic)
    ImageView userPic;
    private Unbinder unbinder;

    public MeFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_me, container, false);
        unbinder = ButterKnife.bind(this, view);

        edit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(getContext(), MeInfoActivity.class));
            }
        });
        return view;
    }

    @Override
    public void updateView() {
        User user = MyApplication.getUser();
        if(user!=null){
            userName.setText(user.getNickname());
            Glide.with(getContext()).load(user.getAvatar()).into(this.userPic);
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
